<template>
  <div
    class="category_control"
    :style="
      screenWidth > 1200
        ? {
            display: 'flex',
          }
        : {}
    "
  >
    <router-link
      :to="{ path: item.path, params: { ...item.params } }"
      v-for="(item, index) in data"
      :key="index"
      :class="'col-md-' + 12 / data.length"
    >
      <div class="es-card">
        <div class="es-card-body">
          <div class="es-avatar">
            <i class="es-avatar-image">
              <img :src="item.avatar" />
            </i>
          </div>
          <h1>{{ item.title }}</h1>
          <p>({{ item.count }} Card)</p>
        </div>
      </div>
    </router-link>
  </div>
</template>

<script>
export default {
  name: "CategoryControl",
  props: {
    data: {
      type: Array,
      default() {
        return [];
      },
    },
  },
  data() {
    return {
      screenWidth: 0,
    };
  },
  created() {
    this.screenWidth = screen.width;
    window.addEventListener("resize", this.reloadPage);
  },
  beforeDestroy() {
    window.removeEventListener("resize", this.reloadPage);
  },
  methods: {
    reloadPage() {
      this.screenWidth = screen.width;
    },
  },
};
</script>

<style lang="scss">
.category_control {
  padding: 0 0 2rem 0;
  .col-md-2 {
    padding: 0;
    margin: 0.625rem 0 0;
    display: inline-table;
  }
  .es-card {
    border: 0;
    box-shadow: 0px 0px 2.5rem rgb(29 58 83 / 10%) !important;
    margin: 0 0.9375rem;
    .es-card-body {
      justify-content: center;
      align-items: center;
      display: flex;
      flex-direction: column;
      h1 {
        font-size: 1rem;
        margin: 0.625rem 0 0;
      }
      p {
        margin: 0.625rem 0 0;
      }
      .es-avatar {
        padding: 0.625rem;
        width: 7rem;
        height: 7rem;
        border-radius: 100%;
      }
      .es-avatar-image {
        width: 100%;
        height: 100%;
      }
    }
  }
}
</style>
